Skip to content

此 PR 完成了 r2cn 测试任务 #1197,新增 -p / --patch 参数到 libra log 命令。#1375

Merged
genedna merged 9 commits into
gitmono-dev:mainfrom
231220075:issue_1197_add_log_p
Aug 27, 2025
Merged

此 PR 完成了 r2cn 测试任务 #1197,新增 -p / --patch 参数到 libra log 命令。#1375
genedna merged 9 commits into
gitmono-dev:mainfrom
231220075:issue_1197_add_log_p

Conversation

@231220075

Copy link
Copy Markdown
Contributor
  1. 在 LogArgs 结构体中增加了 patch(-p/--patch)参数和 pathspec 文件路径参数。
  • log 命令执行时,如果指定 -p,会为每个 commit 生成 diff 并输出。
  • 如果 -p 后跟文件路径,只显示这些文件的 diff。
  1. diff 生成逻辑复用 generate_diff ,根据 pathspec 过滤文件。

  2. 修复了 libra add -A / . 把可执行文件本身加入暂存区的 bug ,使用当前可执行文件的路径进行过滤。

Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
@vercel

vercel Bot commented Aug 25, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
mega Ready Ready Preview Comment Aug 27, 2025 3:08am

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the -p/--patch parameter for the libra log command to display diffs for each commit, similar to Git's git log -p functionality. It also fixes a bug where the executable binary itself was being added to the staging area when using libra add -A or libra add ..

  • Added -p/--patch flag to show commit diffs with optional file path filtering
  • Implemented diff generation logic that reuses existing generate_diff functionality
  • Fixed libra add to exclude the running executable from staging when adding all files

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
libra/src/command/log.rs Adds patch parameter and diff generation logic for log command
libra/src/command/add.rs Fixes bug preventing executable from being added to staging area
libra/tests/command/log_test.rs Updates test to use clap parser for LogArgs construction
aria/contents/docs/libra/command/log/index.mdx Documents the new -p/--patch parameter

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread libra/src/command/log.rs
Comment on lines +233 to +241
let read_content = |file: &PathBuf, hash: &SHA1| {
match load_object::<Blob>(hash) {
Ok(blob) => blob.data,
Err(_) => {
let file = util::to_workdir_path(file);
std::fs::read(&file).unwrap()
}
}
};

Copilot AI Aug 25, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The closure captures variables from the outer scope and has complex error handling. Consider extracting this into a separate function for better readability and testability.

Suggested change
let read_content = |file: &PathBuf, hash: &SHA1| {
match load_object::<Blob>(hash) {
Ok(blob) => blob.data,
Err(_) => {
let file = util::to_workdir_path(file);
std::fs::read(&file).unwrap()
}
}
};
// Use the read_content function instead of a closure
fn read_content(file: &PathBuf, hash: &SHA1) -> Vec<u8> {
match load_object::<Blob>(hash) {
Ok(blob) => blob.data,
Err(_) => {
let file = util::to_workdir_path(file);
std::fs::read(&file).unwrap()
}
}
}

Copilot uses AI. Check for mistakes.
…or the -p parameter

Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
…rs on windows

Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
Signed-off-by: Ruizhi Huang <231220075@smail.nju.edu.cn>
@genedna
genedna added this pull request to the merge queue Aug 27, 2025
Merged via the queue into gitmono-dev:main with commit 449ee5c Aug 27, 2025
12 checks passed
@benjamin-747

Copy link
Copy Markdown
Collaborator

@231220075 请联系genedna@qq.com 讨论实习任务的方向,任务列表可以在https://r2cn.dev/docs/r2cn/projects 找到

@231220075
231220075 deleted the issue_1197_add_log_p branch September 4, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants